package ${packageName}.entity;

import com.baomidou.mybatisplus.annotation.OrderBy;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.baomidou.mybatisplus.annotation.TableName;
import com.spark.common.annotation.Dict;
import com.spark.common.annotation.query.Query;
import com.spark.common.annotation.valid.Password;
import com.spark.common.constants.QueryConstants;
import com.spark.common.constants.RegexConstants;
import com.spark.common.constants.validGroup.AddGroup;
import com.spark.common.constants.validGroup.EditGroup;
<#if model?? && model == "tree">
import com.spark.common.core.entity.BaseTreeEntity;
<#else >
import com.spark.common.core.entity.BaseEntity;
</#if>
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.*;

/**
 * ${functionName}
 *
 * @author ${authorName}
 * @date ${dateTime}
 */
@Data
@TableName("${tableName}")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
<#if model?? && model == "tree">
public class ${ClassName} extends BaseTreeEntity<${ClassName}> {
<#else >
public class ${ClassName} extends BaseEntity {
</#if>

<#list fields as field>
    /**
     * ${field.fieldAnnotation}
    <#if (field.fieldRemark??) && (field.fieldRemark?trim?has_content)>
     *  : ${field.fieldRemark}
    </#if>
     */
    <#-- 查询条件 -->
    <#if field.fieldSelect?? && field.fieldSelect == 1>
    @Query(QueryConstants.QUERY_${field.fieldSelectMode})
    </#if>
    <#-- 排序 -->
    <#if field.fieldSort?? && field.fieldSort == 1>
        <#if field.fieldSortMode?? && field.fieldSortMode == "asc">
    @OrderBy(asc = true, sort = ${field.fieldSortPriority})
        <#else >
    @OrderBy(asc = false, sort = ${field.fieldSortPriority})
        </#if>
    </#if>
    <#-- 是否校验 -->
    <#if field.fieldRule?? && field.fieldRule == 1>
        <#-- 非空校验 -->
        <#if field.fieldRuleNotNull?? && field.fieldRuleNotNull == 1>
            <#if field.fieldPackagePath?contains("String")>
                <#if field.fieldRuleOpportunity??>
                    <#if field.fieldRuleOpportunity == 0>
    @NotBlank(message = "${field.fieldAnnotation}不能为空")
                    <#elseif field.fieldRuleOpportunity == 1>
    @NotBlank(message = "${field.fieldAnnotation}不能为空", groups = {AddGroup.class})
                    <#else >
    @NotBlank(message = "${field.fieldAnnotation}不能为空", groups = {EditGroup.class})
                    </#if>
                </#if>
            <#else >
                <#if field.fieldRuleOpportunity == 0>
    @NotNull(message = "${field.fieldAnnotation}不能为空")
                <#elseif field.fieldRuleOpportunity == 1>
    @NotNull(message = "${field.fieldAnnotation}不能为空", groups = {AddGroup.class})
                <#else >
    @NotNull(message = "${field.fieldAnnotation}不能为空", groups = {EditGroup.class})
                </#if>
            </#if>
        </#if>
        <#-- 数据长度校验 -->
        <#if (field.fieldRuleMin?? && field.fieldRuleMin != 0) && (field.fieldRuleMax?? && field.fieldRuleMax != 0)>
            <#if field.fieldRuleOpportunity == 0>
    @Size(min = ${field.fieldRuleMin}, max = ${field.fieldRuleMax}, message = "${field.fieldAnnotation}长度应在${field.fieldRuleMin}到${field.fieldRuleMax}之间")
            <#elseif field.fieldRuleOpportunity == 1>
    @Size(min = ${field.fieldRuleMin}, max = ${field.fieldRuleMax}, message = "${field.fieldAnnotation}长度应在${field.fieldRuleMin}到${field.fieldRuleMax}之间", groups = {AddGroup.class})
            <#else >
    @Size(min = ${field.fieldRuleMin}, max = ${field.fieldRuleMax}, message = "${field.fieldAnnotation}长度应在${field.fieldRuleMin}到${field.fieldRuleMax}之间", groups = {EditGroup.class})
            </#if>
        <#elseif field.fieldRuleMin?? && field.fieldRuleMin == 0 && field.fieldRuleMax?? && field.fieldRuleMax != 0>
            <#if field.fieldRuleOpportunity == 0>
    @Max(value = ${field.fieldRuleMax}, message = "${field.fieldAnnotation}最多${field.fieldRuleMax}个字符")
            <#elseif field.fieldRuleOpportunity == 1>
    @Max(value = ${field.fieldRuleMax}, message = "${field.fieldAnnotation}最多${field.fieldRuleMax}个字符", groups = {AddGroup.class})
            <#else >
    @Max(value = ${field.fieldRuleMax}, message = "${field.fieldAnnotation}最多${field.fieldRuleMax}个字符", groups = {EditGroup.class})
            </#if>
        <#elseif field.fieldRuleMin?? && field.fieldRuleMin != 0 && (field.fieldRuleMax?? && field.fieldRuleMax == 0)>
            <#if field.fieldRuleOpportunity == 0>
    @Min(value = ${field.fieldRuleMin}, message = "${field.fieldAnnotation}最少${field.fieldRuleMin}个字符")
            <#elseif field.fieldRuleOpportunity == 1>
    @Min(value = ${field.fieldRuleMin}, message = "${field.fieldAnnotation}最少${field.fieldRuleMin}个字符", groups = {AddGroup.class})
            <#else >
    @Min(value = ${field.fieldRuleMin}, message = "${field.fieldAnnotation}最少${field.fieldRuleMin}个字符", groups = {EditGroup.class})
            </#if>
        </#if>
        <#-- 正则校验 -->
        <#if field.fieldRuleRegular?? && field.fieldRuleRegular == 1>
             <#if field.fieldRuleRegularCode??>
                 <#if field.fieldRuleRegularCode == "EMAIL_REGEX">
                     <#if field.fieldRuleOpportunity == 0>
    @Email(message = "请输入有效的电子邮件地址")
                     <#elseif field.fieldRuleOpportunity == 1>
    @Email(message = "请输入有效的电子邮件地址", groups = {AddGroup.class})
                     <#else >
    @Email(message = "请输入有效的电子邮件地址", groups = {EditGroup.class})
                     </#if>
                 <#elseif field.fieldRuleRegularCode == "PASSWORD_REGEX">
                     <#if field.fieldRuleOpportunity == 0>
    @Password
                     <#elseif field.fieldRuleOpportunity == 1>
    @Password(groups = {AddGroup.class})
                     <#else >
    @Password(groups = {EditGroup.class})
                     </#if>
                 <#else >
                     <#if field.fieldRuleOpportunity == 0>
    @Pattern(regexp = RegexConstants.${field.fieldRuleRegularCode}, message = "请输入有效的${field.fieldAnnotation}")
                     <#elseif field.fieldRuleOpportunity == 1>
    @Pattern(regexp = RegexConstants.${field.fieldRuleRegularCode}, message = "请输入有效的${field.fieldAnnotation}", groups = {AddGroup.class})
                     <#else >
    @Pattern(regexp = RegexConstants.${field.fieldRuleRegularCode}, message = "请输入有效的${field.fieldAnnotation}", groups = {EditGroup.class})
                     </#if>
                 </#if>
             <#elseif field.fieldRuleRegularExpression??>
                 <#if field.fieldRuleOpportunity == 0>
    @Pattern(regexp = "${field.fieldRuleRegularExpression}", message = "请输入有效的${field.fieldAnnotation}")
                 <#elseif field.fieldRuleOpportunity == 1>
    @Pattern(regexp = "${field.fieldRuleRegularExpression}", message = "请输入有效的${field.fieldAnnotation}", groups = {AddGroup.class})
                 <#else >
    @Pattern(regexp = "${field.fieldRuleRegularExpression}", message = "请输入有效的${field.fieldAnnotation}", groups = {EditGroup.class})
                 </#if>
             </#if>
        </#if>
    </#if>
    <#-- 字典注解 -->
    <#if field.fieldRelevance?? && field.fieldRelevance == 1>
        <#if field.fieldRelevanceMode?? && field.fieldRelevanceMode == 1>
    @Dict(dictCode = "${field.fieldRelevanceModeValKey}")
        <#else >
    @Dict(dictTable = "${field.fieldRelevanceModeModelCode}", dictCode = "${field.fieldRelevanceModeModelField}", dictText = "${field.fieldRelevanceModeValKey}")
        </#if>
    </#if>
    <#-- 日期时间 -->
    <#if field.componentName??>
        <#if field.componentName == "DateTimePicker">
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        <#elseif field.componentName == "DatePicker">
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
        <#elseif field.componentName == "TimePicker">
    @JsonFormat(timezone = "GMT+8", pattern = "HH:mm:ss")
    @DateTimeFormat(pattern = "HH:mm:ss")
        </#if>
    </#if>
    private ${field.fieldPackagePath} ${field.fieldName};

</#list>
}
